package org.luxor.commons.schedule.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.Length;
import org.luxor.commons.core.utils.DateUtils;
import org.luxor.commons.core.validator.group.AddGroup;
import org.luxor.commons.core.validator.group.UpdateGroup;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date;

/**
 * 定时任务
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.2.0 2016-11-28
 */
@TableName("tb_sys_schedule_job")
public class ScheduleJobEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 任务调度参数key
     */
    public static final String JOB_PARAM_KEY = "JOB_PARAM_KEY";

    /**
     * 任务id
     */
    @TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty(value = "定时任务ID", example = "1")
    private Long id;

    /**
     * 调度类型 (1：Cron表达式  2：fixedRate固定频率  3：fixedDelay固定延时 )
     */
    @NotBlank(message = "调度类型不能为空")
    @Length(message = "调度类型不能超过10个字符", max = 10, groups = {AddGroup.class, UpdateGroup.class})
    @ApiModelProperty(value = "调度类型 (1：Cron表达式  2：fixedRate固定频率  3：fixedDelay固定延时 )")
    private Integer schedulingMode;

    /**
     * spring bean名称
     */
    @NotBlank(message = "bean名称不能为空")
    @Length(message = "bean名称不能超过200个字符", max = 200, groups = {AddGroup.class, UpdateGroup.class})
    @ApiModelProperty(value = "spring bean名称")
    private String beanName;

    /**
     * 方法名
     */
    @NotBlank(message = "方法名称不能为空")
    @Length(message = "方法名称不能超过100个字符", max = 100, groups = {AddGroup.class, UpdateGroup.class})
    @ApiModelProperty(value = "方法名")
    private String methodName;

    /**
     * 参数
     */
    @Length(message = "参数不能超过2000个字符", max = 2000, groups = {AddGroup.class, UpdateGroup.class})
    @ApiModelProperty(value = "json格式参数")
    private String params;

    /**
     * cron表达式
     */
    @ApiModelProperty(value = "cron表达式")
    private String cronExpression;

    /**
     * Determine initial delay (程序启动后延迟{initialDelay}秒执行定时器)
     */
    private Long initialDelay;

    /**
     * fixed delay (【阻塞循环】上一次执行完毕之后{fixedDelay}秒再执行。)
     */
    private Long fixedDelay;

    /**
     * fixed rate (【非阻塞循环】上一次执行时间点之后5秒执行。)
     */
    private Long fixedRate;

    /**
     * 任务状态 (0：正常  1：暂停)
     */
    @NotBlank(message = "任务状态为空")
    @ApiModelProperty(value = "任务状态 (0：正常  1：暂停)")
    private Integer status;

    /**
     * 备注
     */
    @Length(message = "备注不能超过255个字符", max = 255, groups = {AddGroup.class, UpdateGroup.class})
    @ApiModelProperty(value = "备注说明")
    private String remark;

    /**
     * 创建时间
     */
    @NotBlank(message = "创建时间不能为空")
    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN, timezone = "GMT+8")
    private Date createTime;


    public ScheduleJobEntity() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getSchedulingMode() {
        return schedulingMode;
    }

    public void setSchedulingMode(Integer schedulingMode) {
        this.schedulingMode = schedulingMode;
    }

    public String getBeanName() {
        return beanName;
    }

    public void setBeanName(String beanName) {
        this.beanName = beanName;
    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    public String getParams() {
        return params;
    }

    public void setParams(String params) {
        this.params = params;
    }

    public String getCronExpression() {
        return cronExpression;
    }

    public void setCronExpression(String cronExpression) {
        this.cronExpression = cronExpression;
    }

    public Long getInitialDelay() {
        return initialDelay;
    }

    public void setInitialDelay(Long initialDelay) {
        this.initialDelay = initialDelay;
    }

    public Long getFixedDelay() {
        return fixedDelay;
    }

    public void setFixedDelay(Long fixedDelay) {
        this.fixedDelay = fixedDelay;
    }

    public Long getFixedRate() {
        return fixedRate;
    }

    public void setFixedRate(Long fixedRate) {
        this.fixedRate = fixedRate;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Override
    public String toString() {
        return "ScheduleJobEntity{" +
                "id=" + id +
                ", schedulingMode=" + schedulingMode +
                ", beanName='" + beanName + '\'' +
                ", methodName='" + methodName + '\'' +
                ", params='" + params + '\'' +
                ", cronExpression='" + cronExpression + '\'' +
                ", initialDelay=" + initialDelay +
                ", fixedDelay=" + fixedDelay +
                ", fixedRate=" + fixedRate +
                ", status=" + status +
                ", remark='" + remark + '\'' +
                ", createTime=" + createTime +
                '}';
    }
}
